package cn.ch.train.business.controller.admin;

import cn.ch.train.business.request.TrainCarriageQueryParam;
import cn.ch.train.business.request.TrainCarriageSaveParam;
import cn.ch.train.business.response.TrainCarriageQueryResult;
import cn.ch.train.business.service.TrainCarriageService;
import cn.ch.train.common.response.CommonResponse;
import cn.ch.train.common.response.PageResult;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin/train-carriage")
public class TrainCarriageAdminController {
    @Autowired
    private TrainCarriageService trainCarriageService;

    @PostMapping("/save")
    public CommonResponse save(@Valid @RequestBody TrainCarriageSaveParam param) {
        trainCarriageService.save(param);
        return new CommonResponse<>();
    }

    @GetMapping("/query-list")
    public CommonResponse<PageResult<TrainCarriageQueryResult>> queryList(@Valid TrainCarriageQueryParam param) {
        PageResult<TrainCarriageQueryResult> trainCarriageList = trainCarriageService.queryList(param);
        return new CommonResponse<>(trainCarriageList);
    }

    @DeleteMapping("/delete/{id}")
    public CommonResponse delete(@PathVariable Long id) {
        trainCarriageService.delete(id);
        return new CommonResponse<>();
    }

}
